package org.lmw.wechat.ui;

import java.util.ArrayList;
import java.util.List;

import lmw.tools.view.PagerSlidingTabStrip;

import org.lmw.wechat.BaseActivity;
import org.lmw.wechat.BaseFragment;
import org.lmw.wechat.R;
import org.lmw.wechat.ui.frag.MessageFragment;
import org.lmw.wechat.ui.frag.ContactFragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends BaseActivity {
	PagerSlidingTabStrip tabs;
	ViewPager pager;
	List<BaseFragment> fragments;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		init();
	}
	private void init(){
		setContentView(R.layout.activity_main);
		tabs=(PagerSlidingTabStrip)findViewById(R.id.tabs);
		pager=(ViewPager)findViewById(R.id.pager);
		
		fragments=new ArrayList<BaseFragment>();
		fragments.add(new MessageFragment());
		fragments.add(new ContactFragment());
		
		pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
		tabs.setViewPager(pager);
		
	}
	
	String[] titles={"会话","好友"};
	class MyPagerAdapter extends FragmentPagerAdapter{
		public MyPagerAdapter(FragmentManager fm) {
			super(fm);
		}
		@Override
		public int getCount() {
			return titles.length;
		}
		@Override
		public CharSequence getPageTitle(int position) {
			return titles[position];
		}
		@Override
		public Fragment getItem(int position) {
			return fragments.get(position);
		}
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		startActivity(new Intent(getApplicationContext(), SignActivity.class));
		return super.onOptionsItemSelected(item);
	}

}
